package com.uft.was.app;

import java.io.*;

public class ConsoleSimulator
    implements Runnable
{

    public ConsoleSimulator(InputStream is, int type)
    {
        isStop = false;
        this.is = is;
        this.type = type;
    }
    
    public ConsoleSimulator(InputStream is,StringBuffer sb, int type)
    {
        isStop = false;
        this.is = is;
        this.sb=sb;
        this.type = type;
    }

    public void run()
    {
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader reader = new BufferedReader(isr);
        String s;
        try
        {
            while(!isStop && (s = reader.readLine()) != null) 
                if(s.length() != 0) {
                	if(type == 0)
                        System.out.println((new StringBuilder()).append(s).toString());
                    else
                        System.err.println((new StringBuilder()).append(s).toString());
                	if(sb != null){
                		sb.append(s + "\n");
                	}
                }
                    
            		
        }
        catch(IOException ex)
        {
            ex.printStackTrace();
        }
    }

    public void stop()
    {
        isStop = true;
    }

    private volatile boolean isStop;
    private static final int INFO = 0;
    private static final int ERROR = 1;
    private InputStream is;
    private StringBuffer sb= null;
    private int type;
}
